<template>
  <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :show-close="false">
    <p>是否启用当前优惠券？</p>
    <p style="margin-top: 8px;">注：仅启用用户不可主动领取到优惠券；启用并上架用户可直接在小程序领取。</p>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit()">仅启用</el-button>
      <el-button type="primary" @click="submit('on')">启用并上架</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { openUpCoupon } from '../../api/coupon'
export default {
  data() {
    return {
      dialogVisible: false,
      row: ''
    }
  },
  methods: {
    open(row) {
      this.row = row
      this.dialogVisible = true
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    },
    submit(val) {
      this.openUpCouponFun(val)
    },
    // 启用
    openUpCouponFun(val) {
      const { id } = this.row
      const params = {
        // 批次号
        couponId: id,
        // 启用操作 1-仅启用 2-启用并上架
        openUp: val ? 2 : 1
      }
      openUpCoupon(params).then(res => {
        this.dialogVisible = false
        this.resolve && this.resolve()
      })
    }
  }
}
</script>

<style></style>
